function e(e, t, s) {
    return t in e ? Object.defineProperty(e, t, {
        value: s,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = s, e;
}

var t, s = require("../../../utils/function.js"), n = require("../../../api.js"), a = getApp();

Page({
    data: (t = {
        sendtxt: "获取验证码",
        phone: null,
        phoneTest: !1,
        verificationcode: null,
        verificationcodeTest: !1
    }, e(t, "sendtxt", "发送验证码"), e(t, "gettingCode", !0), e(t, "password", null), e(t, "passwordTest", !1), 
    e(t, "successCallback", null), e(t, "agreement", {
        stauts: !1,
        image: "http://run.4hl.cn/addons/sd_drviing/core/public/WeChat/driver/icon-34.png"
    }), t),
    phoneinput: function(e) {
        this.setData({
            phone: e.detail.value
        }), this.phoneTest(e.detail.value);
    },
    phoneTest: function(e) {
        if ("" == e || !/^1\d{10}$/.test(e)) return wx.showToast({
            title: "请输入正确的电话号码格式",
            icon: "none"
        }), void this.setData({
            phoneTest: !1
        });
        this.setData({
            phoneTest: !0
        });
    },
    sendcode: function() {
        var e = this;
        wx.showLoading({}), a.request({
            url: n.user.send_sms,
            method: "post",
            data: {
                phone: e.data.phone
            },
            success: function(t) {
                wx.hideLoading(), 0 != t.code ? (e.setData({
                    gettingCode: !1
                }), e.data.gettingCode = !1, e.countDown()) : s.showToast("验证码获取失败", "none");
            }
        });
    },
    countDown: function() {
        var e = this, t = 59, s = setInterval(function() {
            e.setData({
                sendtxt: t + "s"
            }), --t <= 0 && (s = clearInterval(s), e.setData({
                sendtxt: "获取验证码"
            }), e.setData({
                gettingCode: !0
            }), e.data.gettingCode = !0);
        }, 1e3);
    },
    verificationinput: function(e) {
        this.setData({
            verificationcode: e.detail.value
        }), this.verificationTest(e.detail.value);
    },
    verificationTest: function(e) {
        null != e ? this.setData({
            verificationcodeTest: !0
        }) : wx.showToast({
            title: "请输入验证码",
            icon: "none",
            duration: 5e3
        });
    },
    passwordinput: function(e) {
        console.log(e.detail.value), this.setData({
            password: e.detail.value
        }), this.passwordTest(e.detail.value);
    },
    passwordTest: function(e) {
        "" != e && /^\d{6}$/.test(e) ? this.setData({
            passwordTest: !0
        }) : wx.showToast({
            title: "请输入正确的密码格式",
            icon: "none",
            duration: 5e3
        });
    },
    getPhoneLogin: function() {
        var t = this, s = this.data, o = (s.sendtxt, s.phone), i = s.phoneTest, r = s.verificationcode, d = s.verificationcodeTest, c = (s.password, 
        s.passwordTest), u = (s.successCallback, s.agreement);
        u.stauts && d && c && i ? (wx.showLoading({}), wx.getSetting({
            success: function(s) {
                s.authSetting["scope.userInfo"] && wx.getUserProfile({
                    success: function(s) {
                        console.log("获取用户信息", s), wx.login({
                            success: function(o) {
                                a.request({
                                    url: n.user.login,
                                    method: "post",
                                    data: {
                                        code: o.code,
                                        iv: s.iv,
                                        encryptedData: s.encryptedData
                                    },
                                    success: function(i) {
                                        1 == i.code && (wx.setStorageSync("access_token", i.data.access_token), a.request({
                                            url: n.user.driver_binding_phone,
                                            method: "post",
                                            data: e({
                                                code: o.code,
                                                iv: s.iv,
                                                encryptedData: s.encryptedData,
                                                phone: t.data.phone,
                                                pass: t.data.password,
                                                type: 1
                                            }, "code", t.data.verificationcode),
                                            success: function(e) {
                                                wx.hideLoading(), 0 == e.code ? wx.showToast({
                                                    title: e.msg,
                                                    icon: "none",
                                                    duration: 5e3
                                                }) : (wx.showToast({
                                                    title: "注册成功",
                                                    icon: "none",
                                                    duration: 5e3
                                                }), wx.setStorageSync("userPhone", this.data.phone), wx.redirectTo({
                                                    url: "/pages/driver/personalInformation/personalInformation"
                                                }));
                                            }
                                        }));
                                    }
                                });
                            }
                        });
                    }
                });
            }
        })) : (!u.stauts && this.agreementAndReadTest(), !c && this.passwordTest(o), !d && this.verificationTest(r), 
        !i && this.phoneTest(o));
    },
    agreementAndReadHandler: function() {
        this.data.agreement.status ? this.setData({
            agreement: {
                stauts: !1,
                image: "../../../../images/driver/icon-34.png"
            }
        }) : this.setData({
            agreement: {
                stauts: !0,
                image: "http://run.4hl.cn/addons/sd_drviing/core/public/WeChat/driver/icon-35.png"
            }
        });
    },
    agreementAndReadTest: function() {
        this.data.agreement.stauts || wx.showToast({
            title: " 请勾选我已阅读并同意《代驾服务协议》",
            icon: "none",
            duration: 5e3
        });
    },
    onShareAppMessage: function() {
        return {
            title: a.shareAppMessage().title,
            imageUrl: a.shareAppMessage().imageUrl,
            desc: a.shareAppMessage().desc,
            path: a.shareAppMessage().path
        };
    }
});